<?php
/* --------------------------------------------------------------
   attribute_images.php 2009-12-03 mb
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2009 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/
?><?php

if(defined('_GM_VALID_CALL') === false) die('x0');

// create smarty elements
$smarty = new Smarty;

$options_ids = explode(',', substr($_GET['options_ids'], 0, -1));
$values_ids = explode(',', substr($_GET['values_ids'], 0, -1));

$products_attributes_id = 0;
$attributes = array();

for($i = 0; $i < count($options_ids); $i++){
	$from = strpos($options_ids[$i], '[');
	$products_options_id = substr($options_ids[$i], $from+1, -1);
	$get_attr_data = xtc_db_query("SELECT
																		po.products_options_name,
																		pov.products_options_values_name,
																		pov.gm_filename
																	FROM
																		products_options po,
																		products_options_values pov
																	WHERE
																		po.products_options_id = '" . (int)$products_options_id . "'
																		AND po.language_id = '" . $_SESSION['languages_id'] . "'
																		AND pov.language_id = '" . $_SESSION['languages_id'] . "'
																		AND pov.products_options_values_id = '" . (int)$values_ids[$i] . "'
																	LIMIT 1");
	if(xtc_db_num_rows($get_attr_data) == 1){
		$row = xtc_db_fetch_array($get_attr_data);
		if(!empty($row['gm_filename'])){
			$attributes[] = array('NAME' => $row['products_options_name'],
									'OPTIONS_NAME' =>  $row['products_options_values_name'],
									'IMAGE' => $row['gm_filename']);
		}
	}
}

$smarty->assign('attributes', $attributes);

$smarty->assign('IMAGES_PATH', DIR_WS_CATALOG . DIR_WS_IMAGES . 'product_images/attribute_images/');

$attributes_images = $smarty->fetch(DIR_FS_CATALOG . 'templates/' . CURRENT_TEMPLATE . '/module/gm_attribute_images.html');

echo $attributes_images;

?>